// 莫泰框提示：
function showTip(){
    $("#tipModal").modal('show');
}
function hideTip(){
    $("#tipModal").modal('hide');
}
$("#hideTip").on("click",function(){
    hideTip();
})


//地图容器
var chart = echarts.init(document.getElementById('app'));
var chart1 = echarts.init(document.getElementById('bar_graph'));

//初始化下拉列表的值和文字
var section1_val = -1;
var section1_text = '';
var section2_val = -1;
var section2_text = '';
var section3_val = -1;
var section3_text = '';

//监听下拉列表的变动
$('#section1').on('change',function () {
   section1_val = $('#section1 option:selected').val();
   section1_text = $('#section1 option:selected').text();
});

$('#section2').on('change',function () {
    section2_val = $('#section2 option:selected').val();
    section2_text = $('#section2 option:selected').text();
});

$('#section3').on('change',function () {
    section3_val = $('#section3 option:selected').val();
    section3_text = $('#section3 option:selected').text();
});

window.onresize = function(){
    chart.resize();
    chart1.resize();
};

//34个省、市、自治区的名字拼音映射数组
var provinces = {
    //23个省
    "台湾省": "taiwan",
    "河北省": "hebei",
    "山西省": "shanxi",
    "辽宁省": "liaoning",
    "吉林省": "jilin",
    "黑龙江省": "heilongjiang",
    "江苏省": "jiangsu",
    "浙江省": "zhejiang",
    "安徽省": "anhui",
    "福建省": "fujian",
    "江西省": "jiangxi",
    "山东省": "shandong",
    "河南省": "henan",
    "湖北省": "hubei",
    "湖南省": "hunan",
    "广东省": "guangdong",
    "海南省": "hainan",
    "四川省": "sichuan",
    "贵州省": "guizhou",
    "云南省": "yunnan",
    "陕西省": "shanxi1",
    "甘肃省": "gansu",
    "青海省": "qinghai",
    //5个自治区
    "新疆维吾尔自治区": "xinjiang",
    "广西壮族自治区": "guangxi",
    "内蒙古自治区": "neimenggu",
    "宁夏回族自治区": "ningxia",
    "西藏自治区": "xizang",
    //4个直辖市
    "北京市": "beijing",
    "天津市": "tianjin",
    "上海市": "shanghai",
    "重庆市": "chongqing",
    //2个特别行政区
    "香港": "xianggang",
    "澳门": "aomen"
};

//34个省、市、自治区的代码映射数组
var provCode = {
    //23个省
    "台湾省": "710000",
    "河北省": "130000",
    "山西省": "140000",
    "辽宁省": "210000",
    "吉林省": "220000",
    "黑龙江省": "230000",
    "江苏省": "320000",
    "浙江省": "330000",
    "安徽省": "340000",
    "福建省": "350000",
    "江西省": "360000",
    "山东省": "370000",
    "河南省": "410000",
    "湖北省": "420000",
    "湖南省": "430000",
    "广东省": "440000",
    "海南省": "460000",
    "四川省": "510000",
    "贵州省": "520000",
    "云南省": "530000",
    "陕西省": "610000",
    "甘肃省": "620000",
    "青海省": "630000",
    //5个自治区
    "新疆维吾尔自治区": "650000",
    "广西壮族自治区": "450000",
    "内蒙古自治区": "150000",
    "宁夏回族自治区": "640000",
    "西藏自治区": "540000",
    //4个直辖市
    "北京市": "110000",
    "天津市": "120000",
    "上海市": "310000",
    "重庆市": "500000",
    //2个特别行政区
    "港澳":"910000"
};

//直辖市和特别行政区-只有二级地图，没有三级地图
var special = ["北京市","天津市","上海市","重庆市","香港","澳门"];

//直辖市code映射
var specialCode ={
    "beijing":"北京市",
    "tianjin":"天津市",
    "shanghai":"上海市",
    "chongqing":"重庆市",
    "xianggang":"香港",
    "aomen":"澳门"
}

//江苏地级市
var JSCitys = ["南京市","无锡市","徐州市","常州市","苏州市","南通市","连云港市","淮安市","盐城市","扬州市","镇江市","泰州市","宿迁市"];

//柱状图数据
var flag = [];//柱状图点击标记
var dataB= { "智能装备":[0,0,0,0],"电子信息":[0,0,0,0],"新材料":[0,0,0,0],"航空航天":[0,0,0,0],"生物技术与新医药":[0,0,0,0],"能源与环保":[0,0,0,0],"管理":[0,0,0,0],"其他":[0,0,0,0] }
var mapdata = [];
//绘制江苏省地图
$.getJSON('map/province/jiangsu.json', function(data){
    var d = [];
    for( var i=0;i<data.features.length;i++ ){
        d.push({
            name:data.features[i].properties.name
        })
    }
    mapdata = d;
    //注册地图
    echarts.registerMap('jiangsu', data);
    //绘制地图
    renderMap('jiangsu',d);
});

//地图点击事件
chart.on('click', function (params) {
    if( JSCitys.indexOf(params.name) >=0 ){
        //显示县级地图
        $.getJSON('map/city/'+ cityMap[params.name] +'.json', function(data){
            echarts.registerMap( params.name, data);
            var d = [];
            for( var i=0;i<data.features.length;i++ ){
                d.push({
                    name:data.features[i].properties.name
                })
            }
            renderMap(params.name,d);
        });
    }else{
        renderMap('jiangsu',mapdata);
    }
});

//初始化地图配置
var option = {
    backgroundColor: '#acbad5',
    title : {
        text: '军民科技协同创新资源地图',
        x: 'center',
        y:'5',
        textStyle:{
            color: '#fff',
        },
    },
    tooltip: {
        trigger: 'item',
        formatter: function (params) {
            return params.name;
        }
    },
    animationDuration:1000,
    animationEasing:'cubicOut',
    animationDurationUpdate:1000

};

function renderMap(map,data){
    option.series = [
        {
            name: map,
            type: 'map',
            mapType:map,
            roam: false,
            nameMap:{
                'china':'中国'
            },
            label: {
                normal:{
                    show:true,
                    textStyle:{
                        color:'#fff',
                        fontSize:13
                    }
                },
                emphasis: {
                    show: true,
                    textStyle:{
                        color:'#000',
                        fontSize:13
                    }
                }
            },
            itemStyle: {
                normal: {
                    areaColor: '#323c48',
                    borderColor: 'dodgerblue'
                },
                emphasis: {
                    areaColor: 'darkorange'
                }
            },
            data:data,
        },
    ];
    //设置配置项
    chart.setOption(option);
}

//调用接口取数据
function getData(site,section1_val,section1_text,section2_val,section2_text,section3_val) {

    //资源类型映射
    var resources = {
        '1':'xq',
        '2':'cg',
        '3':'zj',
        '4':'qy',
    };

    var d ={
        1:'需求',
        2:'成果',
        3:'专家',
        4:'企业',
    };

    //定义接口参数
    var dataVal = [];

    //对参数处理
    var sel2_val = section2_val == "-1"? null: [section2_val];
    var sel3_val = section3_val == "-1"? null: [section3_val];

    //获取统计数据
    $.ajax({
        url: restUrl + '/index/libcount',
        type: 'post',
        dataType: 'json',
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify({
            "formType": resources[section1_val],
            "site": site,
            "sex": "0",
            "domain": "1",
            "education": "0",
            "degree": "0",
            "sites": sel2_val,
            "sexs": null,
            "domains": sel3_val,
            "educations": null,
            "degrees": null
        }),
        success: function (v) {
            if (v.code == '10000') {
                //拿取统计值放入数组
                var arr = [];
                var country =[];

                for(var i=0;i<v.data.lib.length;i++) {
                    if(v.data.lib[i].country !=""){
                        //定义下标
                        var index = country.indexOf(v.data.lib[i].country);

                        //去重(按城市统计）
                        if(index =="-1"){
                            arr.push(v.data.lib[i].count);
                            country.push(v.data.lib[i].country);
                        } else {
                            arr[index] = arr[index] + v.data.lib[i].count;
                        }

                    }
                }

                //更新柱状图
                reBar(arr,country,d[section1_val],section1_val,section3_val);

                //赋值给数据源
                for(var i=0;i<country.length;i++){
                    dataVal.push({ name: country[i], value: arr[i] });
                }

                //计算统计值中的最大值并配置给地图的等高线
                var max = arr[0];
                for (var i = 0; i < arr.length - 1; i++) {
                    max = max < arr[i+1] ? arr[i+1] : max
                }
                max = max + 20;

                if(dataVal.length == 0){

                    //修改配置项
                    option.title.text = "无数据";
                    $('#section2').empty();
                    $('#section2').append("<option value='-1' disabled selected>江苏省</option>");
                    //绘制地图
                    renderMap('jiangsu',mapdata);
                } else {
                    //重新渲染地图
                    remap(site,max,dataVal,section1_val,section1_text,section2_val,section2_text,section3_val);
                }
            }else {
                console.log(v.message)
            }
        },
        error:function (data) {
            console.log(data)
        }
    })
}

//地图铺值，重新渲染
function remap(site,max,dataVal,section1_val,section1_text,section2_val,section2_text){

    //地图标题
    var subName = section2_val == '-1'? '总体': section2_text;
    var MapName = section1_text + '分布图(' + subName +')';

    //banner标题赋值
    $('.destination').html(MapName);

    //修改配置
    option.title.text = MapName;
    option.tooltip.formatter = function (params) {
        for(var i = 0; i < dataVal.length; i++){
            if( dataVal[i].name == params.name ) {
                return params.name + ' : ' + dataVal[i].value;
            }
        }
        return params.name;
    };
    option.visualMap = {
        min: 0,
        max: max,
        calculable: true,
        inRange: {
            color: ['#50a3ba', '#eac736', '#d94e5d']
        },
        textStyle: {
            color: '#fff'
        }
    };
    option.series = [
        {
            name: section2_val =="-1" ? 'china': provinces[section2_text],
            type: 'map',
            mapType: section2_val =="-1" ? 'china': provinces[section2_text],
            roam: false,
            nameMap: {
                'china': '中国'
            },
            label: {
                normal: {
                    show: true,
                    textStyle: {
                        color: '#fff',
                        fontSize: 11
                    }
                },
                emphasis: {
                    show: true,
                    textStyle: {
                        color: '#000',
                        fontSize: 11
                    }
                }
            },
            itemStyle: {
                normal: {
                    areaColor: '#323c48',
                    borderColor: 'dodgerblue'
                },
                emphasis: {
                    areaColor: 'darkorange'
                }
            },
            data: dataVal,
        },
    ]

    //渲染中国地图
    if(section2_val == '-1'){
        $.getJSON('map/china.json', function(data) {

            //注册地图
            echarts.registerMap('china', data);
            chart.setOption(option);

        })
    } else {
        //渲染省级地图
        if(section2_text in provinces ){
            $.getJSON('map/province/' + provinces[section2_text] + '.json', function (data) {

                //注册地图
                echarts.registerMap(provinces[section2_text], data);
                chart.setOption(option);

            })
        } else {
            //渲染市级地图
            $.getJSON('map/city/'+ cityMap[section2_text] +'.json', function(data){

                option.series[0].name = section2_text;
                option.series[0].mapType = section2_text;
                //注册地图
                echarts.registerMap(section2_text, data);
                chart.setOption(option);
            })
        }

    }

}

//调取接口获得柱状图数据
function getBarData(section1_val){

    //资源类型映射
    var resources = {
        '1':'xq',
        '2':'cg',
        '3':'zj',
        '4':'qy',
    };

    //定义数据接口
    var dataBar = [];

    //获取统计数据
    $.ajax({
        url: restUrl + '/index/libcount',
        type: 'post',
        dataType: 'json',
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify({
            "formType": resources[section1_val],
            "site": "1",
            "sex": "0",
            "domain": "1",
            "education": "0",
            "degree": "0",
            "sites": null,
            "sexs": null,
            "domains": null,
            "educations": null,
            "degrees": null
        }),
        success: function (v) {
            if (v.code == '10000') {

                //拿取统计值放入数组
                var arr= [];
                var domains = [];

                if(section1_val == 3){
                    for(var i=0;i<v.data.lib.length;i++) {
                        if(v.data.lib[i].country !=""){
                            //定义下标
                            var index = domains.indexOf(v.data.lib[i].researchField);

                            //去重(按领域统计）
                            if(index == "-1"){
                                arr.push(v.data.lib[i].count);
                                domains.push(v.data.lib[i].researchField);
                            } else {
                                arr[index] = arr[index] + v.data.lib[i].count;
                            }
                        }
                    }
                }else {
                    for(var i=0;i<v.data.lib.length;i++) {
                        if(v.data.lib[i].country !=""){
                            //定义下标
                            var index = domains.indexOf(v.data.lib[i].domain);

                            //去重(按领域统计）
                            if(index == "-1"){
                                arr.push(v.data.lib[i].count);
                                domains.push(v.data.lib[i].domain);
                            } else {
                                arr[index] = arr[index] + v.data.lib[i].count;
                            }
                        }
                    }
                }

                //赋值给数据源
                for(var i=0;i<domains.length;i++){
                    if(domains[i] !=""){
                        dataBar.push({name: domains[i], value: arr[i] });
                    }
                }

                //获取柱状图的数据源
                var znsb = [],dzxx = [],xcl = [],hkht = [],swyy = [],nyhb = [],gl = [],other = [];
                var x =  ["智能装备","电子信息","新材料","航空航天","生物技术与新医药","能源与环保","管理","其他"];

                for(var i=0;i<dataBar.length;i++){
                    dataB[dataBar[i].name][section1_val-1] = dataBar[i].value;
                }

                znsb = dataB[x[0]];
                dzxx = dataB[x[1]];
                xcl = dataB[x[2]];
                hkht = dataB[x[3]];
                swyy = dataB[x[4]];
                nyhb = dataB[x[5]];
                gl = dataB[x[6]];
                other = dataB[x[7]];

                initBar(znsb,dzxx,xcl,hkht,swyy,nyhb,gl,other,x);

            } else {
                console.log(v.message)
            }
        },
        error:function (data) {
            console.log(data)
        }
    })

};
getBarData(1);
getBarData(2);
getBarData(3);
getBarData(4);

//初始化柱状图
function initBar(znsb,dzxx,xcl,hkht,swyy,nyhb,gl,other,x){

    chart1.clear();
    // 柱状图配置项
    var option1 = {
        backgroundColor:'#e6f4ff',
        color: ['#003366', '#006699', '#4cabce', '#e5323e','rgba(0,208,208,.8)','#ADFF2F','#acbad5','#ec6841'],
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        legend: {
            x:'center',
            y:'5',
            data:x
        },
        xAxis: [
            {
                type: 'category',
                axisTick: {show: false},
                data: ['需求', '成果', '专家', '企业',]
            }
        ],
        yAxis: [
            {
                type:'value'
            }
        ],
        series: [
            {
                name: '智能装备',
                type: 'bar',
                data: znsb
            },
            {
                name: '电子信息',
                type: 'bar',
                data: dzxx
            },
            {
                name: '新材料',
                type: 'bar',
                data: xcl
            },
            {
                name: '航空航天',
                type: 'bar',
                data: hkht
            },
            {
                name: '生物技术与新医药',
                type: 'bar',
                data: swyy
            },
            {
                name: '能源与环保',
                type: 'bar',
                data: nyhb
            },
            {
                name: '管理',
                type: 'bar',
                data: gl
            },
            {
                name: '其他',
                type: 'bar',
                data: other
            },
        ]
    };
    chart1.setOption(option1);

}

//根据调取的接口参数重置柱状图
function reBar(arr,country,name){

    //清空图表实例
    chart1.clear();

    //重新配置配置项
    var options = {
        backgroundColor:'#e6f4ff',
        color: ['#006699'],
        title: {
            x:'center',
            y:'5',
            text: '军民科技协同创新资源分布图('+ name + ')'
        },
        tooltip: {},
        legend: {
            x:'right',
            y:'30',
            data:[name]
        },
        xAxis: {
            type: 'category',
            data: country,
            axisLabel: {
                interval: 0,
                rotate: 40
            }
            },
        yAxis: {},
        series: [{
            name: name,
            type: 'bar',
            data: arr
        }]
    };
    chart1.setOption(options);

};

//获得列表数据
function getTable(section1_val,objName,province){

    var d = {
        '1':'Requirements',
        '2':'Harvests',
        '3':'experts',
        '4':'Enterprises',
    };

    var filed = {
        "智能装备": "1",
        "电子信息": "2",
        "新材料": "3",
        "航空航天": "4",
        "生物技术与新医药": "5",
        "能源与环保": "6",
        "管理": "7",
        "其他": "99"
    };

    //定义接口数据
    var data1 = [];
    var data2 = [];

    $.ajax({
        url: restUrl + '/index/lib/' + d[section1_val],
        type: 'get',
        dataType: 'json',
        data:{
            loadAll:true,
            needPaging: false,
            objDomain:filed[objName],
            province:province,
        },
        success:function (v) {
            if(v.code == '10000'){
                var half = Math.floor(v.data.rows.length/2);
                //取前一半数据放入data1
                for(var i=0;i<half;i++){
                    if(section1_val == 1){
                        data1.push([ v.data.rows[i].reqName,v.data.rows[i].name,v.data.rows[i].domain ]);
                    }else if(section1_val ==2){
                        data1.push([ v.data.rows[i].resName,v.data.rows[i].name,v.data.rows[i].domain ]);
                    }else if(section1_val ==3){
                        data1.push([ v.data.rows[i].name,v.data.rows[i].workUnit,v.data.rows[i].researchField ]);
                    }else {
                        data1.push([ v.data.rows[i].name,v.data.rows[i].product,v.data.rows[i].domain ]);
                    }
                }
                //取后一半数据放入data2
                for(var i= half;i<v.data.rows.length;i++){
                    if(section1_val == 1){
                        data2.push([ v.data.rows[i].reqName,v.data.rows[i].name,v.data.rows[i].domain ]);
                    }else if(section1_val ==2){
                        data2.push([ v.data.rows[i].resName,v.data.rows[i].name,v.data.rows[i].domain ]);
                    }else if(section1_val ==3){
                        data2.push([ v.data.rows[i].name,v.data.rows[i].workUnit,v.data.rows[i].researchField ]);
                    }else {
                        data2.push([ v.data.rows[i].name,v.data.rows[i].product,v.data.rows[i].domain ]);
                    }
                }

                var table1 = $('#myTable1').DataTable();
                var table2 = $('#myTable2').DataTable();
                table1.destroy();
                table2.destroy();

                if(section1_val == 1){

                    $('#myTable1').DataTable({
                        "language": {
                            "info": "第_PAGE_页(共_PAGES_页）",
                            "emptyTable": "请根据条件检索",
                            "infoEmpty": "没有记录可以显示",
                            "loadingRecords": "请等待，数据正在加载中......",
                            "paginate": {
                                'next': '下一页',
                                'previous': '上一页',
                            }
                        },
                        "searching":false,
                        "info":false,
                        "ordering": false,
                        "lengthChange": false,
                        "deferRender": true,
                        lengthMenu:[5],
                        columns: [
                            { title: "需求名称" },
                            { title: "来源" },
                            { title: "所属领域", width: "25%"  },
                        ],
                        data:data1
                    });

                    $('#myTable2').DataTable({
                        "language": {
                            "info": "第_PAGE_页(共_PAGES_页）",
                            "emptyTable": "请根据条件检索",
                            "infoEmpty": "没有记录可以显示",
                            "loadingRecords": "请等待，数据正在加载中......",
                            "paginate": {
                                'next': '下一页',
                                'previous': '上一页',
                            }
                        },
                        "searching":false,
                        "info":false,
                        "ordering": false,
                        "lengthChange": false,
                        "deferRender": true,
                        lengthMenu:[5],
                        columns: [
                            { title: "需求名称" },
                            { title: "来源" },
                            { title: "所属领域", width: "25%"  },
                        ],
                        data:data2
                    });

                    //设置表格大小一致
                    if($('#myTable1').height()> $('#myTable2').height()){
                        $('#myTable2').css('height',$('#myTable1').height())
                    } else if($('#myTable1').height()< $('#myTable2').height()){
                        $('#myTable1').css('height',$('#myTable2').height())
                    } else {}
                }else if(section1_val ==2){

                    $('#myTable1').DataTable({
                        "language": {
                            "info": "第_PAGE_页(共_PAGES_页）",
                            "emptyTable": "请根据条件检索",
                            "infoEmpty": "没有记录可以显示",
                            "loadingRecords": "请等待，数据正在加载中......",
                            "paginate": {
                                'next': '下一页',
                                'previous': '上一页',
                            }
                        },
                        "searching":false,
                        "info":false,
                        "ordering": false,
                        "lengthChange": false,
                        "deferRender": true,
                        lengthMenu:[5],
                        columns: [
                            { title: "成果名称" },
                            { title: "来源" },
                            { title: "所属领域", width: "25%"  },
                        ],
                        data:data1
                    });

                    $('#myTable2').DataTable({
                        "language": {
                            "info": "第_PAGE_页(共_PAGES_页）",
                            "emptyTable": "请根据条件检索",
                            "infoEmpty": "没有记录可以显示",
                            "loadingRecords": "请等待，数据正在加载中......",
                            "paginate": {
                                'next': '下一页',
                                'previous': '上一页',
                            }
                        },
                        "searching":false,
                        "info":false,
                        "ordering": false,
                        "lengthChange": false,
                        "deferRender": true,
                        lengthMenu:[5],
                        columns: [
                            { title: "成果名称" },
                            { title: "来源" },
                            { title: "所属领域", width: "25%"  },
                        ],
                        data:data2
                    });

                    //设置表格大小一致
                    if($('#myTable1').height()> $('#myTable2').height()){
                        $('#myTable2').css('height',$('#myTable1').height())
                    } else if($('#myTable1').height()< $('#myTable2').height()){
                        $('#myTable1').css('height',$('#myTable2').height())
                    } else {}
                }else if(section1_val ==3){

                    $('#myTable1').DataTable({
                        "language": {
                            "info": "第_PAGE_页(共_PAGES_页）",
                            "emptyTable": "请根据条件检索",
                            "infoEmpty": "没有记录可以显示",
                            "loadingRecords": "请等待，数据正在加载中......",
                            "paginate": {
                                'next': '下一页',
                                'previous': '上一页',
                            }
                        },
                        "searching":false,
                        "info":false,
                        "ordering": false,
                        "lengthChange": false,
                        "deferRender": true,
                        lengthMenu:[5],
                        columns: [
                            { title: "专家姓名", width: "20%" },
                            { title: "工作单位" },
                            { title: "研究领域" },
                        ],
                        data:data1
                    });

                    $('#myTable2').DataTable({
                        "language": {
                            "info": "第_PAGE_页(共_PAGES_页）",
                            "emptyTable": "请根据条件检索",
                            "infoEmpty": "没有记录可以显示",
                            "loadingRecords": "请等待，数据正在加载中......",
                            "paginate": {
                                'next': '下一页',
                                'previous': '上一页',
                            }
                        },
                        "searching":false,
                        "info":false,
                        "ordering": false,
                        "lengthChange": false,
                        "deferRender": true,
                        lengthMenu:[5],
                        columns: [
                            { title: "专家姓名", width: "20%" },
                            { title: "工作单位" },
                            { title: "研究领域" },
                        ],
                        data:data2
                    });

                    //设置表格大小一致
                    if($('#myTable1').height()> $('#myTable2').height()){
                        $('#myTable2').css('height',$('#myTable1').height())
                    } else if($('#myTable1').height()< $('#myTable2').height()){
                        $('#myTable1').css('height',$('#myTable2').height())
                    } else {}
                }else {

                    $('#myTable1').DataTable({
                        "language": {
                            "info": "第_PAGE_页(共_PAGES_页）",
                            "emptyTable": "请根据条件检索",
                            "infoEmpty": "没有记录可以显示",
                            "loadingRecords": "请等待，数据正在加载中......",
                            "paginate": {
                                'next': '下一页',
                                'previous': '上一页',
                            }
                        },
                        "searching":false,
                        "info":false,
                        "ordering": false,
                        "lengthChange": false,
                        "deferRender": true,
                        lengthMenu:[5],
                        columns: [
                            { title: "企业名称" },
                            { title: "主营产品" },
                            { title: "所属领域", width: "25%" },
                        ],
                        data:data1
                    });

                    $('#myTable2').DataTable({
                        "language": {
                            "info": "第_PAGE_页(共_PAGES_页）",
                            "emptyTable": "请根据条件检索",
                            "infoEmpty": "没有记录可以显示",
                            "loadingRecords": "请等待，数据正在加载中......",
                            "paginate": {
                                'next': '下一页',
                                'previous': '上一页',
                            }
                        },
                        "searching":false,
                        "info":false,
                        "ordering": false,
                        "lengthChange": false,
                        "deferRender": true,
                        lengthMenu:[5],
                        columns: [
                            { title: "企业名称" },
                            { title: "主营产品" },
                            { title: "所属领域", width: "25%" },
                        ],
                        data:data2
                    });

                    //设置表格大小一致
                    if($('#myTable1').height()> $('#myTable2').height()){
                        $('#myTable2').css('height',$('#myTable1').height())
                    } else if($('#myTable1').height()< $('#myTable2').height()){
                        $('#myTable1').css('height',$('#myTable2').height())
                    } else {}
                }

            } else {
                console.log(v.message)
            }
        },
        error:function (data) {
            console.log(data)
        }
    })
};

//根据检索内容调整地图
$('.map_submit').on('click',function () {

    if(section1_val == -1){ showTip();}

    //定义总查询方式为省级
    var site = 1;
    if(section2_val !='-1'){
        if(vk[0][section2_text][0].substr(2,4) =='0000'){
            if(  special.indexOf( section2_text ) >=0) {
                site = 3
            }else {
                site = 2
            }
        }else {
            site = 3
        }
    }

    //根据资料库中查询的结果，判定数据是否来自同一省份,调用方法获取参数
    var isTrue = sessionStorage.getItem('isTrue');
    var p = sessionStorage.getItem('prov').split(',');
    if(isTrue == 'true'){
        if(section2_val !='-1'){
            getData(site,section1_val,section1_text,section2_val,section2_text,section3_val);
        }else {
            getData(2,section1_val,section1_text,p[1],p[0],section3_val);
        }
    } else {
        getData(site,section1_val,section1_text,section2_val,section2_text,section3_val);
    }

    var text1 = section2_val == '-1' ? '': section2_text;
    var text2 = section3_val == '-1' ? '': section3_text;

    //调用方法获取列表
    getTable(section1_val,text2,text1);
});

//刷新页面
$('.map_refresh').on('click',function () {
    window.location.reload();
});

/**
 * KV配对
 * 调接口拿取KV
 */
var kv = [];
var vk = [];
function getKV() {

    //拿code
    $.ajax({
        url:restUrl + '/index/pcaa',
        type:'get',
        dataType:'json',
        data:{},
        success:function (v) {
            if(v.code == '10000'){
                vk.push(v.data.vk);
                kv.push(v.data.kv);
            }else {
                console.log(v.message)
            }
        },
        error:function (data) {
            console.log(data)
        }
    });
}
getKV();

/**
 * 地图的点击方法
 */
var showFieldData = "";
//修改地图点击的方法
chart.on('click',function (params) {

    if(  special.indexOf( params.name ) >=0  ) {
        site = 3
    }else {
        site = 2
    }

    //取省的缩写，用于做对比
    var provs = [];
    for(key in provinces){
        provs.push(provinces[key]);
    }

    //点击不含数据的省市区，重新刷新地图
    if(params.name ==""){

        //修改配置项
        option.series[0].data = dataVal;
        option.series[0].name = params.seriesName;
        option.series[0].mapType = params.seriesName;

        if(params.seriesName == "china"){
            $.getJSON('map/' + params.seriesName + '.json', function(data) {

                //注册地图
                echarts.registerMap(params.seriesName, data);
                chart.setOption(option);
            })
        } else if(provs.indexOf(params.seriesName) >=0){
            $.getJSON('map/province/' + params.seriesName + '.json', function(data) {

                //注册地图
                echarts.registerMap(params.seriesName, data);
                chart.setOption(option);
            })
        } else {
            $.getJSON('map/city/'+ cityMap[params.seriesName] +'.json', function(data){

                //注册地图
                echarts.registerMap(section2_text, data);
                chart.setOption(option);
            })
        }

    } else {
        //点击含数据的省市，进入下一级地图
        if (params.name in provinces) {
            getData(site, section1_val, section1_text, vk[0][params.name][0], params.name, section3_val);
            showFieldData = params.name;
        } else if (provs.indexOf(params.seriesName) >=0){
            //点击直辖市的地级市回到中国地图（没有三级）
            if(  special.indexOf( specialCode[params.seriesName] ) >=0  ) {
                getData(1,section1_val,section1_text,-1,"a",-1);
            }else {
                //点击带数据的城市（有三级城市）

                getData(3,section1_val,section1_text,vk[0][params.name][0],params.name,section3_val);
                showFieldData = params.name;
            }
        }else {
            //点击的是区级
            var isTrue = sessionStorage.getItem('isTrue');
            var p = sessionStorage.getItem('prov').split(',');
            if(isTrue == 'true'){
                getData(2,section1_val,section1_text,p[1],p[0],section3_val);
                showFieldData = p[0];
            } else {
                getData(1,section1_val,section1_text,-1,"a",-1);
            }

        }
    }
    // 查询列表
    var text2 = section3_val == '-1' ? '': section3_text;

    //调用方法获取列表
    getTable(section1_val,text2,showFieldData);
})

/**
 *柱状图的点击方法
 */
//点击柱状图
chart1.on('click',function (params) {

    //映射
    var resource = {
        '需求': '1',
        '成果': '2',
        '专家': '3',
        '企业': '4'
    };

    var d = {
        '1':'需求',
        '2':'成果',
        '3':'专家',
        '4':'企业'
    };

    var preName = '军民科技协同创新';

    //把点击的名称依次记录入数组备用
    flag.push(params.name);

    //如果点击的是省市区
    if(params.name in vk[0]) {

        //点击的是省
        if (vk[0][params.name][0].substr(2, 4) == '0000') {

            //点击的是省里面的直辖市
            if(  special.indexOf( params.name ) >=0  ) {

                var sel1_name = preName + params.seriesName;
                getData(3,section1_val,sel1_name,vk[0][params.name][0],params.name,section3_val);

            } else {
                //点击的是省里面的非直辖市
                //父级元素为4大资源
                if(params.seriesName in resource){

                    var sel1_name = preName + params.seriesName;
                    getData(2,section1_val,sel1_name,vk[0][params.name][0],params.name,section3_val);

                }
            }

        } else if (vk[0][params.name][0].substr(4, 2) == '00') {
            //点击的是城市

            var sel1_name = preName + d[section1_val];
            getData(3,section1_val,sel1_name,vk[0][params.name][0],params.name,section3_val);
        } else {
            //点击的是区
            var isTrue = sessionStorage.getItem('isTrue');
            var p = sessionStorage.getItem('prov').split(',');
            var sel1_name = preName + d[section1_val];
            if(isTrue == 'true'){
                getData(2,section1_val,sel1_name,p[1],p[0],section3_val);
            } else {

                getData(1,section1_val,sel1_name,-1,'a',section3_val);
            }

        }

    } else if(params.name in resource){
        //点击的是4大资源

        var sel1_name = preName + params.name;
        getData(1,resource[params.name],sel1_name,-1,params.name,section3_val);
    } else {
        //点击的是领域

    }

});
